Guest User

Untitled

a guest
Nov 4th, 2011
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.81 KB | None | 0 0
  1. /* Godzio 10 */
  2.  
  3. #include <stdio.h>
  4. #include <math.h>
  5.  
  6.  
  7. #define SIZE 10
  8.  
  9. float avg(float array[], int size) {
  10.     float sum=0;
  11.     int i;
  12.    
  13.     for (i=0; i<size; i++)
  14.         sum += array[i];
  15.    
  16.     return sum/size;
  17. }
  18.  
  19. float odchylenie(float array[], int size) {
  20.     float avrg = avg(array, size);
  21.     float result=0;
  22.     float expression;
  23.     int i;
  24.    
  25.     for (i=0; i<size; i++) {
  26.         expression = array[i] - avrg;
  27.         result += expression*expression;
  28.     }
  29.    
  30.     result = sqrt(result/size);
  31.    
  32.     return result;
  33. }
  34.    
  35.  
  36. int main (void) {
  37.     float tab[SIZE];
  38.     int i;
  39.     float E;
  40.     float S;
  41.    
  42.     for (i=0; i<SIZE; i++) {
  43.         tab[i] = sqrt(i);
  44.         printf("tab[%d] = %f\n", i, tab[i]);
  45.     }
  46.    
  47.     E = avg(tab, SIZE);
  48.     printf("Srednia to: %f\n", E);
  49.     S = odchylenie(tab, SIZE);
  50.     printf("Odchylenie standardowe to: %f\n", S);
  51.        
  52.    
  53.    
  54.    
  55.     return 0;
  56. }
  57.  
  58.  
Advertisement
Add Comment
Please, Sign In to add comment